using System;
using System.Windows.Forms;

namespace Tino
{
    public partial class IconPickerForm : Form
    {
        ImageList images;

        public int SelectedImageIndex
        {
            get { return imagesListView.SelectedIndices[0]; }
        }

        public IconPickerForm(ImageList Images)
        {
            InitializeComponent();
            images = Images;

            setImagesListView();
        }

        void setImagesListView()
        {
            imagesListView.LargeImageList = images;

            for (int i = 0; i < images.Images.Count; i++)
            {
                imagesListView.Items.Add("", i);
            }
        }

        void list_DoubleClick(object sender, EventArgs e)
        {
            if (SelectedImageIndex > -1)
            {
                DialogResult = DialogResult.OK;
                Close();
            }
        }

        void okButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            Close();
        }

        void cancelButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }

        void Form_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                DialogResult = DialogResult.Cancel;
                Close();
            }
        } 
    }
}